<?php
/****************************/
/* http://www.17buyhost.com */
/*  QQ 11203691             */
/****************************/
if ( !defined( "IN_UCHOME" ) )
{
	exit( "Access Denied" );
}
//获得用户的UID
if ( empty( $uid ) )
{
	$uid = $_SGLOBAL['supe_uid'];
}
//判断游客是否可以浏览爆料
if($confignewss['noreg']==0){//游客是否可以浏览爆料,0为必须登陆
	checklogin( );
}
//分页
$perpage = 10;
$list = $ols = $fuids = array();
$page = empty($_GET['page'])?0:intval($_GET['page']);
if($page<1) $page = 1;
$start = ($page-1)*$perpage;
//检查开始数
ckstart($start, $perpage);
$actives = array($_GET['view']=>' class="active"');
if($_GET['view'] == 'all'  or !isset($_GET['view'] ) ) {//所有爆料
	$theurl = 'news.php?&do=news&view=all';
	$sql='select a.province as province,a.city as city,a.subcity as subcity,a.up as up,a.pic as pic,
			a.id as newsid,a.ip as ip,c.catname as catname,a.catid as catid,b.uid as uid,
			b.username as username,starttime,endtime,subject,detail from '
			.$_SC['tablepre'].'news_detail as a,'.$_SC['tablepre'].'member as b, '
			.$_SC['tablepre'].'news_category as c where a.uid=b.uid and c.catid=a.catid 
			and  pass=0   ';
	$query = $_SGLOBAL['db']->query( $sql );
    $count=mysql_num_rows($query);
    $sql.=' order by a.up desc,starttime desc LIMIT '.$start.','.$perpage;
 
    $actives = array('all'=>' class="active"');	
}
if($_GET['view'] == 'me' ) {//我的爆料
	$theurl = 'news.php?&do=news&view=me';
	$sql='select  a.province as province,a.city as city,a.subcity as subcity,a.up as up,a.pic as pic,
			a.id as newsid,a.ip as ip, c.catname as catname,a.catid as catid,b.uid as uid,
			b.username as username,starttime,endtime,subject,detail from '
			.$_SC['tablepre'].'news_detail as a,'.$_SC['tablepre'].'member as b, '
			.$_SC['tablepre'].'news_category as c where a.uid=b.uid and c.catid=a.catid 
			and   pass=0   and  b.uid='.$uid;	
	$query = $_SGLOBAL['db']->query( $sql );
    $count=mysql_num_rows($query);
    $sql.=' order by a.up desc,starttime desc LIMIT '.$start.','.$perpage;	
}
if($_GET['view'] == 'friend' ) {//好友的爆料
	$theurl = 'news.php?&do=news&view=friend';
	$sql='select  a.province as province,a.city as city,a.subcity as subcity,a.up as up,a.pic as pic,
			a.id as newsid,a.ip as ip, c.catname as catname,a.catid as catid,b.uid as uid,
			b.username as username,starttime,endtime,subject,detail from '
			.$_SC['tablepre'].'news_detail as a,'.$_SC['tablepre'].'member as b, '
			.$_SC['tablepre'].'news_category as c where a.uid=b.uid and c.catid=a.catid 
			and   pass=0   and  b.uid IN (select fuid from uchome_friend where   uid='.$uid.')';	
	$query = $_SGLOBAL['db']->query( $sql );
    $count=mysql_num_rows($query);
    $sql.=' order by a.up desc,starttime desc LIMIT '.$start.','.$perpage;	
}
if($_GET['view'] == 'find'){//搜索爆料
	$showfind=true;
	$sql='select  a.province as province,a.city as city,a.subcity as subcity,a.up as up,a.pic as pic,
			a.id as newsid,a.ip as ip,c.catname as catname,a.catid as catid,b.uid as uid,
			b.username as username,starttime,endtime,subject,detail from '.
			$_SC['tablepre'].'news_detail as a,'.$_SC['tablepre'].'member as b, '
			.$_SC['tablepre'].'news_category as c where a.uid=b.uid and c.catid=a.catid 
			and pass=0   ';
			
	$catid=$_POST['catid']?$_POST['catid']:$_GET['catid'];
	if(intval($catid)>0 ) 
		$sql.=' and (c.catid='.$catid.' or c.parentid='.$catid.')';
	$keyword =$_POST['keyword']?$_POST['keyword']:$_GET['keyword'];
	$province =$_POST['province']?$_POST['province']:$_GET['province'];
	$city =$_POST['city']?$_POST['city']:$_GET['city'];
	$subcity =$_POST['subcity']?$_POST['subcity']:$_GET['subcity'];
	$searchtype =$_POST['searchtype']?$_POST['searchtype']:$_GET['searchtype'];
	if(!$searchtype) $sql.=" and subject like '%".$keyword."%'";
	if($searchtype=='1') $sql.=" and detail like '%".$keyword."%'";
	$theurl = 'news.php?&do=news&view=find&catid='.intval($_GET['catid']).
				'&keyword='.$keyword.'&province='.$province.'&city='.$city.
				'&subcity='.$city.'&subcity='.$subcity.'&searchtype='.$searchtype;
	if($province) $sql.=" and province like '%".$province."%' ";
	if($city) $sql.=" and city like '%".$city."%' ";
	if($subcity) $sql.=" and subcity like '%".$subcity."%' ";
  	$query = $_SGLOBAL['db']->query( $sql );
   	$count=mysql_num_rows($query);
 	$sql.=' order by a.up desc,starttime desc LIMIT '.$start.','.$perpage;
	$actives = array('find'=>' class="active"');
}
if(empty($sql)) showmessage('非法的请求参数!', 'news.php',5);
$query = $_SGLOBAL['db']->query( $sql );
while ($result=mysql_fetch_array($query,1)){
	$temp_news['detail']=$result['detail'];
	$quote_attachurl = preg_quote($_SC['attachurl'], '/');
	if(preg_match("/http:\/\//i",$result['pic'],$temp)){
		$temp_news['pic']=$result['pic'];	
	}elseif(!empty($result['pic'])){
		if(preg_match("/$quote_attachurl/",$result['pic'],$temp))
			$temp_news['pic'] = $result['pic'];
		else 
			$temp_news['pic']= $_SC['attachurl'].$result['pic'];
	}else { 
	    $temp_news['pic']='';
	}
	$temp_news['catname']=$result['catname'];
	$temp_news['uid']=$result['uid'];
 	$temp_news['username']=$result['username'];
	$temp_news['starttime']=$result['starttime'];
	$temp_news['province']=$result['province'];
	$temp_news['city']=$result['city'];
	$temp_news['endtime']=$result['endtime'];
	$temp_news['subject']=$result['subject'];
	$temp_news['detail']=getstr($result['detail'], 300, 0, 0, 0, 0, -1);
	$temp_news['catid']=$result['catid'];
	$temp_news['ip']=$result['ip'];
	$temp_news['up']=$result['up'];
	$temp_news['newsid']=$result['newsid'];
	$list[]=$temp_news;
}
$isadmin=ckadmin($_SGLOBAL['supe_uid']);
$multi['html']=multi($count, $perpage, $page, $theurl);

$_TPL['css'] = 'blog';
include_once( template( "news/template/news" ));

?>

